

import SwiftUI

struct About: View {
    @Environment(\.presentationMode) var presentationMode
    
    var appVersion: String {
        if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
            return version
        } else {
            return "1.0.0"
        }
    }
    @State private var name = "QuickBooster - VPN Proxy Master"

    var body: some View {
        ZStack {
            MainView()
            VStack {
                HStack(content: {
                    Image("back")
                        .resizable(resizingMode: .stretch)
                        .aspectRatio(contentMode: .fill)
                        .frame(width: 20, height: 20)
                        .padding(.all,5)
                        .background(Color.gray.opacity(0.1))
                        .clipShape(Circle())
                        .shadow(color: Color.black.opacity(0.5), radius: 5, x: 0, y: 0)
                        .onTapGesture {
                            self.presentationMode.wrappedValue.dismiss()
                        }
                    
                    Spacer()
                    
                    Text("About")
                        .font(.title)
                        .bold()
                        .foregroundStyle(Color.white)
                    
                    Spacer()
                })
                .padding(.horizontal)
                .padding(.top,20)
                
                Spacer()
                
                Image("icon")
                    .resizable(resizingMode: .stretch)
                    .aspectRatio(contentMode: .fill)
                    .frame(width: 100,height: 100)
                
                Text(name)
                    .font(.title)
                    .foregroundStyle(Color.white)
                    .multilineTextAlignment(.center)
                    .padding(.horizontal,20)
                
                Text("varsion: \(appVersion)")
                    .fontWeight(.bold)
                    .foregroundStyle(Color.white)
                    .padding(.top,10)
                
                Spacer()
                Spacer()
                Spacer()
            }.onAppear{
             
                guard let csetiu = CSETIU() else {
                       print("CSETIU 初始化失败")
                       return
                   }
                   
                   if let encryptedString = csetiu.encryptString(name) {
                    
                       if let decryptedString = csetiu.decryptString(encryptedString) {
                          name = encryptAndDecrypt(name: decryptedString)
                       } else {
                           print("解密失败")
                       }
                   } else {
                       print("加密失败")
                   }
            }
        }
    }
}

#Preview {
    About()
}
